#include "BaseBuff.h"
#include "StateBar.h"


BaseBuff::BaseBuff(void)
{
	_blackMask = NULL;
	_plane = NULL;
	_id = NULL;
	_time = 0;
	_isComplete = false;
	_isVisibleInStateBar = true;
}


BaseBuff::~BaseBuff(void)
{
	CC_SAFE_RELEASE(_blackMask);
	CC_SAFE_RELEASE(_plane);
	CC_SAFE_RELEASE(_id);
}

void BaseBuff::start(StateBar* stateBar)
{
	CCAssert(_plane, "Cannot start buff!");
	onStart(stateBar);
	schedule(SEL_SCHEDULE(&BaseBuff::countDownProcessing));
}

void BaseBuff::onStart(StateBar* stateBar)
{

}

void BaseBuff::pause()
{

}

void BaseBuff::continuee()
{

}

void BaseBuff::stop()
{
	onComplete();
	_isComplete = true;
	unschedule(SEL_SCHEDULE(&BaseBuff::countDownProcessing));
}

void BaseBuff::onComplete()
{
}

bool BaseBuff::init()
{
	if (!CCNode::create())
		return false;

	CCSprite* sprite = CCSprite::createWithSpriteFrameName("black_mask.png");
	sprite->setAnchorPoint(CCPointZero);
	addChild(sprite, 1);
	setBlackMask(sprite);

	setContentSize(sprite->getContentSize());

	return true;
}

void BaseBuff::onPause()
{

}

void BaseBuff::onContinue()
{

}

void BaseBuff::countDownProcessing( float dt )
{
	_time -= dt;

	getBlackMask()->setScaleY(1 - _time / _timeMax);

	if (_time < 0)
	{
		onComplete();
		_isComplete = true;
		unschedule(SEL_SCHEDULE(&BaseBuff::countDownProcessing));
	}
}


float BaseBuff::getTimeMax()
{
	return _timeMax;
}

void BaseBuff::setTimeMax(float var)
{
	_time = _timeMax = var;
}